/* s2 - compare byte arrays
   Copyright (C) 2019 Ariadne Devos

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#include <stddef.h>
#include <sHT/index.h>
#include <sHT/string.h>
#include <sHT/test.h>

size_t
sHT_memeq(const char *buffer0, const char *buffer1, size_t correct, size_t otherwise, size_t length)
{
	size_t i;
	/* TODO: optimise -- but without Spectre issues
	   Perhaps do a word at a time. */
	sHT_index_iterate(i, length) {
		/* @var{sHT_and_none} is incorrect here! Strings can contain NUL. */
		if (sHT_neq(buffer0[i], buffer1[i]))
			return otherwise;
	}
	return correct;
}
